#include "pagespdlmtreason.h"
#include "ui_pagespdlmtreason.h"

PageSpdLmtReason::PageSpdLmtReason(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PageSpdLmtReason)
{
    ui->setupUi(this);
    setAutoFillBackground(true);  //设置自动填充
    QPalette palette = BKGCLR;
    setPalette(palette);

    m_lReasonList.append(ui->spdlimit_1);m_lReasonStat.append(0);
    m_lReasonList.append(ui->spdlimit_2);m_lReasonStat.append(0);
    m_lReasonList.append(ui->spdlimit_3);m_lReasonStat.append(0);
    m_lReasonList.append(ui->spdlimit_4);m_lReasonStat.append(0);
    m_lReasonList.append(ui->spdlimit_5);m_lReasonStat.append(0);
    m_lReasonList.append(ui->spdlimit_6);m_lReasonStat.append(0);
    m_lReasonList.append(ui->spdlimit_7);m_lReasonStat.append(0);
    m_lReasonList.append(ui->spdlimit_8);m_lReasonStat.append(0);
}

PageSpdLmtReason::~PageSpdLmtReason()
{
    delete ui;
}

void PageSpdLmtReason::on_Btn_Return_clicked()
{
    emit signal_go_back();
}

void PageSpdLmtReason::setEPFltCount(uint8_t cnt)
{
    if(cnt > 0)
    {
        ui->label_EPFlt->setStyleSheet("background-color:rgb(255,0,0);font:18pt 'Arial';color:rgb(255,255,255);border-radius:5px;");
        ui->EPFltCnt->setStyleSheet("background-color:rgb(255,0,0);font:18pt 'Arial';color:rgb(255,255,255);border-radius:5px;");

    }
    else
    {
        ui->label_EPFlt->setStyleSheet("background-color:rgb(64,64,64);font:18pt 'Arial';color:rgb(255,255,255);border-radius:5px;");
        ui->EPFltCnt->setStyleSheet("background-color:rgb(64,64,64);font:18pt 'Arial';color:rgb(255,255,255);border-radius:5px;");
    }
    ui->EPFltCnt->setText(QString().setNum(cnt));
}

void PageSpdLmtReason::setEDFltCount(uint8_t cnt)
{
    if(cnt > 0)
    {
        ui->label_EDFlt->setStyleSheet("background-color:rgb(255,0,0);font:18pt 'Arial';color:rgb(255,255,255);border-radius:5px;");
        ui->EDFltCnt->setStyleSheet("background-color:rgb(255,0,0);font:18pt 'Arial';color:rgb(255,255,255);border-radius:5px;");

    }
    else
    {
        ui->label_EDFlt->setStyleSheet("background-color:rgb(64,64,64);font:18pt 'Arial';color:rgb(255,255,255);border-radius:5px;");
        ui->EDFltCnt->setStyleSheet("background-color:rgb(64,64,64);font:18pt 'Arial';color:rgb(255,255,255);border-radius:5px;");
    }
    ui->EDFltCnt->setText(QString().setNum(cnt));
}

void PageSpdLmtReason::setTracFltCount(uint8_t cnt)
{
    if(cnt > 0)
    {
        ui->label_TracFlt->setStyleSheet("background-color:rgb(255,0,0);font:18pt 'Arial';color:rgb(255,255,255);border-radius:5px;");
        ui->TracFltCnt->setStyleSheet("background-color:rgb(255,0,0);font:18pt 'Arial';color:rgb(255,255,255);border-radius:5px;");

    }
    else
    {
        ui->label_TracFlt->setStyleSheet("background-color:rgb(64,64,64);font:18pt 'Arial';color:rgb(255,255,255);border-radius:5px;");
        ui->TracFltCnt->setStyleSheet("background-color:rgb(64,64,64);font:18pt 'Arial';color:rgb(255,255,255);border-radius:5px;");
    }
    ui->TracFltCnt->setText(QString().setNum(cnt));
}

void PageSpdLmtReason::setSpeedlimtReason(uint8_t index, bool xActive)
{
    if(xActive)
        m_lReasonList[index]->setStyleSheet("background-color:rgb(255,0,0);font:18pt 'Arial';color:rgb(255,255,255);border-radius:5px;");
    else
        m_lReasonList[index]->setStyleSheet("background-color:rgb(64,64,64);font:18pt 'Arial';color:rgb(255,255,255);border-radius:5px;");
    m_lReasonStat[index] = xActive;
    if(m_lReasonStat.contains(1))
        emit signal_speedlimt_act(true);
    else
        emit signal_speedlimt_act(false);
}
